/*
 * rb112.h
 *
 *  Created on: 13 May 2015
 *      Author: yiqi.pan
 */

#ifndef SRC_RB112_H_
#define SRC_RB112_H_

enum
{
	RB_R_OK = 1,
	RB_R_FAIL,
	RB_R_CMD_ERROR,
	RB_R_TIMEOUT
} ;

enum
{
	CMD_NONE,
	CMD_GET_VERSION,
	CMD_GET_NAME,
	CMD_GET_PIN,
	CMD_GET_COD,
	CMD_GET_BTADDR,
	CMD_GET_BAUD,
	CMD_GETIOCAP,
	CMD_GET_SPP_DISCOVERABLE,
	CMD_TEST, // first set command
	CMD_SET_NAME,
	CMD_SET_PIN,
	CMD_SET_COD,
	CMD_SET_SPP_DISCOVERABLE,
	NR_OF_COMMAND // last command
} ;



#define is_get_command(cmd) ( cmd > CMD_NONE && cmd < CMD_TEST)
#define is_set_command(cmd) ( cmd >= CMD_TEST && cmd < NR_OF_COMMAND)

#define RB_GET_TIMEOUT 1 // milliseconds
#define RB_SET_TIMEOUT 15 // milliseconds
/* initialise RB112 module and GPIO pins */
void rb_bt_init(void);

uint8_t rb_send_get_cmd(uint8_t cmdid, uint8_t* buf, uint8_t buflen);

uint8_t rb_send_set_cmd(uint8_t cmdid, uint8_t *data, uint8_t datalen);


/* check if a uart connect is established over bluetooth */
void rb_bt_is_connected(void);

/* disconnect the current connection */
void rb_bt_disconnect(void);

/* hard reset bluetooth module */
void rb_bt_hw_reset(void);

/* configure the RB112 for the first time */
void rb_config(void);

/* send data via bluetooth uart */
void rb_bt_send(uint8_t* data, uint8_t datalen);

int8_t rb_receive_handler(uint8_t* data, uint8_t datalen);


#endif /* SRC_RB112_H_ */
